package Thread;
//获取线程引用

class MyThread4 extends Thread{
    //如果是继承Thread，直接使用this拿到线程实例
    //如果是Runnable或者lambda的方式，就不可以，因为此时的this已经不再指向Thread对象了
    //就只能使用Thread.currentThread()了
    @Override
    public void run() {
        System.out.println(this.getId()+","+this.getName());
    }
}
public class ThreadDemo13 {
    public static void main(String[] args) throws InterruptedException {
        MyThread4 t1=new MyThread4();
        MyThread4 t2=new MyThread4();
        t1.start();
        t2.start();
        Thread.sleep(1000);
        System.out.println(t1.getId()+","+t1.getName());//与run方法里面执行结果是一样的
        System.out.println(t2.getId()+","+t2.getName());
    }
}
